﻿using System;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using EmptyWallGallery.Core;
using EmptyWallGallery.Core.Utilities;
using Microsoft.VisualBasic;

namespace EmptyWallGallery.FrontEnd.inside.Editor.Products
{
    public partial class CreatePhoto : Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (IsPostBack) return;
            if (Request.QueryString["AlbumId"] == null) Response.Redirect("Album.aspx");
            if (!Common.Instance.IsNumeric(Request.QueryString["AlbumId"])) Response.Redirect("Album.aspx");

            AlbumId = Request.QueryString["AlbumId"];
            UserName = HttpContext.Current.User.Identity.Name;
            UserId = Membership.GetUser(UserName).ProviderUserKey.ToString();

            var albumItem = Core.BLL.Album.Instance.GetById(Convert.ToInt32(AlbumId));
            headTitle.InnerText += ": " + albumItem.AlbumName;

            BindData(Convert.ToInt32(AlbumId), 0);
        }

        public void BindData(int albumId, int status)
        {
            lstPhoto.DataSource = Core.BLL.Images.Instance.GetByAlbum(status, albumId, true);
            lstPhoto.DataBind();
        }

        protected string WriteImage(string fileName, DateTime createDate, string uploadBy)
        {
            var objUser = Membership.GetUser(Guid.Parse(uploadBy));
            if (objUser == null) return "";

            var strImageDefault = fileName == ""
                                      ? "/images/no-image.jpg"
                                      : "/Uploads/" + objUser.UserName + "/" + createDate.Year + "/" +
                                        Common.Instance.Right("0" + createDate.Month, 2) + "/" +
                                        Common.Instance.Right("0" + createDate.Day, 2) + "/";

            return "<a href=\"" + strImageDefault + "700x0__" + fileName + "\" rel=\"TopProduct\"><img src=\"" +
                   strImageDefault + "135x0__" + fileName + "\" border=\"0\" width=\"130\" /></a>";
        }

        protected string WriteCreateDate(string toString)
        {
            return Strings.Format(DateTime.Parse(toString).AddHours(Configs.TimeLine),
                                  "dd-MM-yyyy");
        }

        protected void LstPhotoPreRender(object sender, EventArgs e)
        {

        }

        protected string UserId { get; set; }
        protected string UserName { get; set; }
        protected string AlbumId { get; set; }
    }
}